package lesson04;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public class TestMain4 {
    public static void main(String[] args) {

        Collection<String> a1 = new HashSet<>();
        System.out.println(a1.size());
        System.out.println(a1.add("hello world"));
        System.out.println(a1.add("Tom krols"));
        System.out.println(a1.add("威亚"));
        System.out.println(a1.add("威亚")); // 失败了
        System.out.println(a1.size());
        System.out.println("-----增强for-------");
        for (String item: a1) {
            System.out.println(item);
        }
        System.out.println("----Lambda--------");
        // lambda 函数式接口
        a1.stream().forEach(System.out::println);
        System.out.println("-----迭代器-------");
        // 迭代器循环
        Iterator<String> it = a1.iterator(); // 获取迭代器
        while (it.hasNext()) {
            String item = it.next();
            System.out.println(item);
        }
        System.out.println("------------");
    }
}
